import {defineStore} from 'pinia'
import {navApi} from "@/api/blog/navApi";

// 第一个参数是应用程序中 store 的唯一 id
export const navStore = defineStore('nav', {
    // 推荐使用 完整类型推断的箭头函数
    state: ()  => {
        return {
            navList: [] as Menu[],
            collapsed: false
        }
    },
    getters: {
        getNavList: (state) : Menu[]  => {
            return state.navList
        },
        getCollapsed: (state) : boolean => {
            return state.collapsed
        }
    },
    actions: {
        initNavList () {
            navApi.getNavTreeList().then(res => {
                this.$state.navList = res.data
                console.log('initNavList',this.$state.navList)
            })
        },
        changeCollapsed () {
            this.$state.collapsed = !this.$state.collapsed
        }
    },
    // 表示这个store里的数据都将持久化存储
    persist: true
})
